package com.jams.rbac.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.rbac.api.entity.Dept;
import com.jams.rbac.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 部门管理
 *
 * @author linxb
 * @date 2020-01-07 19:23:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dept")
@Api(value = "dept", tags = "部门管理管理")
public class DeptController {

    private final  DeptService deptService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dept 部门管理
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getDeptPage(Page page, Dept dept) {
        return JamsResponse.ok(deptService.page(page, Wrappers.query(dept)));
    }

    /**
     * 列表查询
     * @param dept 部门管理
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public JamsResponse getDeptList(Dept dept) {
        return JamsResponse.ok(deptService.list(Wrappers.query(dept)));
    }

    /**
     * 通过id查询部门管理
     * @param deptId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{deptId}")
    public JamsResponse getById(@PathVariable("deptId") Long deptId) {
        return JamsResponse.ok(deptService.getById(deptId));
    }

    /**
     * 新增部门管理
     * @param dept 部门管理
     * @return JamsResponse
     */
    @ApiOperation(value = "新增部门管理", notes = "新增部门管理")
    @PostMapping
    public JamsResponse save(@RequestBody Dept dept) {
        return JamsResponse.ok(deptService.save(dept));
    }

    /**
     * 修改部门管理
     * @param dept 部门管理
     * @return JamsResponse
     */
    @ApiOperation(value = "修改部门管理", notes = "修改部门管理")
    @PutMapping
    public JamsResponse updateById(@RequestBody Dept dept) {
        return JamsResponse.ok(deptService.updateById(dept));
    }

    /**
     * 通过id删除部门管理
     * @param deptId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除部门管理", notes = "通过id删除部门管理")
    @DeleteMapping("/{deptId}")
    public JamsResponse removeById(@PathVariable Long deptId) {
        return JamsResponse.ok(deptService.removeById(deptId));
    }

}
